//
//  TableViewCellContentView.m
//  OTOClient
//
//  Created by Suny on 15/3/29.
//  Copyright (c) 2015年 Suny. All rights reserved.
//

#import "TableViewCellContentView.h"
@interface TableViewCellContentView ()
//@property (nonatomic,strong)TableViewCellDisplayInfo *displayInfo;

@end

@implementation TableViewCellContentView

- (void)dealloc
{
	for (UIGestureRecognizer *gesTureRecognizer in self.gestureRecognizers) {
		[self removeGestureRecognizer:gesTureRecognizer];
	}

}

- (id)init
{
	self = [super init];
	if (self)
	{
//		UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
//																							   action:@selector(tapGestureRecognizerHandle:)];
//		[self addGestureRecognizer:tapGestureRecognizer];
	}
	
	return self;
}

- (instancetype)initWithDisplayInfo:(TableViewCellDisplayInfo *)displayInfo
{
    self = [super init];
    if (self)
    {
        self.displayInfo = displayInfo;
    }

    return self;
}

+ (instancetype)viewWithDisplayInfo:(TableViewCellDisplayInfo *)displayInfo
{
    return [[self alloc] initWithDisplayInfo:displayInfo];
}


- (void)updateDisplayInfo:(TableViewCellDisplayInfo *)displayInfo
{
	if ([displayInfo.modelInfo isKindOfClass:[NSString class]])
	{
		self.titleLabel.text = (NSString *)displayInfo.modelInfo;
		self.displayInfo.modelInfo = displayInfo;
	}
	else
	{
		if (displayInfo != _displayInfo)
		{
			self.displayInfo = displayInfo;
		}
	}

}


- (UILabel *)titleLabel
{
	if (!_textLabel)
	{
		_textLabel = [[UILabel alloc] initWithFrame:self.bounds];
		_textLabel.backgroundColor = [UIColor clearColor];
		_textLabel.textAlignment = NSTextAlignmentCenter;
		
		[self addSubview:_textLabel];
		
	}
	return _textLabel;
}



- (void)tapGestureRecognizerHandle:(UIGestureRecognizer *)gestureRecognize
{
	NSLog(@"%@",gestureRecognize.view);
	
	TableViewCellContentView *cellContentView = (TableViewCellContentView *)gestureRecognize.view;
	id objectModel = cellContentView.displayInfo.modelInfo;
	if ([objectModel respondsToSelector:@selector(clickedInModelEntityModelCell)])
	{
		[objectModel clickedInModelEntityModelCell];
	}
	
}
@end
